package com.example.qxfw.jtyb.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.zy.Traffic;
import com.example.qxfw.common.util.DateUtil;
import com.example.qxfw.jtyb.service.GsglybService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;
import java.util.List;

@ApiIgnore
@Api(tags = "交通预报-高速公路预报")
@RestController
@CrossOrigin
@RequestMapping("/gsglyb")
public class GsglybController {
    @Autowired
    private GsglybService gsglybService;


    @ApiOperation("获取交通预报表所有信息")
    @GetMapping("/getAllOfTraffic")
    public SysResult getAllOfTraffic(){
        List<Traffic> list = gsglybService.getAllOfTraffic();
        return SysResult.success(list);
    }

    @ApiOperation("根据日期类型时次时效查询交通预报表")
    @GetMapping("/selectByDateTypeNtimestimecharOfTraffic")
    public SysResult selectByDateTypeNtimestimecharOfTraffic(
            String announcedtime, Integer forecasttype, Integer ntimes, String timechar
    ){
        StringBuilder sb = new StringBuilder();
        sb.append(announcedtime);
        sb.append(" ");
        sb.append(timechar);
        Date date = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(sb.toString()));
        List<Traffic> list = gsglybService.selectByDateTypeNtimestimecharOfTraffic(date, forecasttype, ntimes);
        return SysResult.success(list);
    }

}
